package org.mobile.logic;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import org.mobile.beans.User;
import org.mobile.database.connection.ConnectionManager;
import org.mobile.database.statements.Statements;

public class AJAXvalidationLogic {
	
	public static boolean checkLogin(String login) {
			Connection conn= null;
			PreparedStatement st= null;
			ResultSet rs= null;
			
			conn= ConnectionManager.getManager().getConnection();
			try {
				st= conn.prepareStatement(Statements.SELECT_USER);
				st.setString(1, login);
				rs= st.executeQuery();
				if(rs.next()){
					return true;
				}
				else {
					return false;
				}
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} 
			finally{
				try {
					rs.close();
					st.close();
				} catch (SQLException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
			
			return false;
	}
	
	public static boolean checkModel(String model) {
		Connection conn= null;
		PreparedStatement st= null;
		ResultSet rs= null;
		
		conn= ConnectionManager.getManager().getConnection();
		try {
			st= conn.prepareStatement(Statements.SELECT_PHONE_BY_MODEL_NAME);
			st.setString(1, model);
			rs= st.executeQuery();
			System.out.println();
			if(rs.next()){
				return true;
			}
			else {
				return false;
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} 
		finally{
			try {
				rs.close();
				st.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		
		return false;
}
}
